from typing import Any, Dict, List, Optional
from app.utils.logger import logger

def validate_required_fields(data: Dict[str, Any], required_fields: List[str]) -> Optional[List[str]]:
    """
    验证数据中是否包含所有必填字段
    
    :param data: 待验证的数据字典
    :param required_fields: 必填字段列表
    :return: 缺失的字段列表，如果没有缺失则返回None
    """
    missing_fields = [field for field in required_fields if field not in data]
    
    if missing_fields:
        logger.warning(f"缺失必填字段: {', '.join(missing_fields)}")
        return missing_fields
    
    return None

def validate_field_type(data: Dict[str, Any], field: str, expected_type) -> bool:
    """
    验证字段类型是否符合预期
    
    :param data: 数据字典
    :param field: 字段名
    :param expected_type: 预期类型
    :return: 类型是否匹配
    """
    if field not in data:
        return False
        
    return isinstance(data[field], expected_type)
